package com.pc.web.orders;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.pc.web.goods.GoodsBeans;
import com.pc.web.goods.GoodsController;
import com.pc.web.member.MemberBeans;
import com.pc.web.member.MemberService;

@Controller
public class OrdersController {

	@Autowired
	private OrdersDao dao;
	@Autowired
	private OrdersService service;
	@Autowired
	private MemberService mservice;
	@Autowired
	private GoodsController gController;

	// 홈
	@RequestMapping(value = "/orders/home", method = RequestMethod.GET)
	public String home() {
		return "/orders/orders_home";
	}

	// 주문 정보 입력(쓰기 페이지)
	@RequestMapping(value = "/orders/write", method = RequestMethod.GET)
	public String writePage(GoodsBeans gbeans, String goods_code,Model model, HttpSession session, MemberBeans beans) {
		mservice.getUserProfile(model, session, beans);
		gController.detail(gbeans, model, goods_code);
		return "/orders/orders_write";
	}

	// 주문 정보 입력(쓰면서 읽기 서비스)
	@RequestMapping(value = "/orders/write", method = RequestMethod.POST)
	public String write(String orders_payment, ReceiverBeans beans, Model model, ReceiverBeans rebeans) {
		service.read(orders_payment, beans, model, rebeans);
		return "/orders/orders_read";
	}
	
	// 읽기
	@RequestMapping(value = "/orders/read", method = RequestMethod.GET)
	public String read() {
		return "/orders/orders_read";
	}

	// 결제 읽기
	@RequestMapping(value = "/orders/payment", method = RequestMethod.POST)
	public String payment(String pay, ReceiverBeans beans, Model model) {
		service.payment(pay, beans, model);
		return "/orders/orders_payment";
	}

	// 주문 배송 조회(리스트)
	@RequestMapping(value = "/orders/list", method = RequestMethod.GET)
	public String list(Model model) {
		List<ReceiverBeans> list = service.list();
		model.addAttribute("beans", list);
		return "/orders/orders_list";
	}

	// 결제 읽기
	@RequestMapping(value = "/orders/view", method = RequestMethod.GET)
	public String view(String pay, ReceiverBeans beans, Model model) {
		service.payment(pay, beans, model);
		return "/orders/orders_view";
	}

	// 우편번호 찾기 페이지
	@RequestMapping(value = "/orders/zipcode", method = RequestMethod.GET)
	public String zipcode() {
		return "/orders/orders_zipcode";
	}

}
